package com.hj.authority.security;

import com.hj.authority.domain.entity.SysUser;
import com.hj.authority.service.SysUserService;
import com.hj.exception.HjException;
import com.hj.i18n.ResourcesI18n;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;


/**
 * @author hj
 * @Date 2023/4/26
 * @Description:
 */
@Service(value = "hjUserDetails")
@Slf4j
public class MobileUserDetailsServiceImpl implements MobileUserDetailsService {

    @Resource
    private SysUserService sysUserService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUser userEntity = sysUserService.getByUsername(username);
        if (null == userEntity) {
            String message = ResourcesI18n.getMessage("DYY(104|用户不存在)");
            System.out.println(message);
            throw new HjException(104, message);
        }
        return sysUserService.getUserDetails(userEntity);

    }

}
